<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#detailPan {
	width: 100%;
	height: 100%;
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.deepDark {
	background-color: #CCC488;
}

.normalDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">
	var radioValue = [ {
		id : 1,
		text : "在职"
	}, {
		id : 0,
		text : "已离职"
	} ];
	var sexData = [ {
		id : 1,
		text : "男"
	}, {
		id : 0,
		text : "女"
	} ];
</script>

</head>
<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="300px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a> 企业：<span
					class="nameTitle">未选择</span></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;
						入职日期:&nbsp;&nbsp;<input id="starting"
						class="mini-datepicker" style="width: 100px;" showNullItem="false"
						valueField="" onvalidation="" allowInput="false"
						emptyText="起始期间..." nullItemText="&lt;无&gt;" /> <span
						style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect_2" tooltip="查询" plain="false">查询</a>
				</span><a width="100px"></a> &nbsp;&nbsp;<span id="separatorId2"
					class="separator"> <a class="mini-button" id="addBtn"
						iconCls="icon-ok" plain="false" onclick="ok">确定</a></span></td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div class="mini-splitter" style="width: 100%; height: 100%;">
			<div size="320px" showCollapseButton="true">
				<div id="treegrid1" class="mini-treegrid"
					style="height: 100%; width: 100%;" showTreeIcon="true"
					borderStyle="border:1;" onbeforeload="treeBeforeLoad" pagesize="50"
					sizeList="[50,100,200,500]" showPager="false" treeColumn="OrgName"
					idField="OrgNo" ondrawcell="ondatagridDrawCell"
					onrowclick="orgSelect" parentField="ParentNo" resultAsTree="false"
					expandOnLoad="true" showPageInfo="false" showFilterRow="true">
					<div property="columns">
						<div type="checkcolumn" field="Action" width="70px"
							headerAlign="center" align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch()">清除
							</a>
						</div>
						<div name="OrgName" field="OrgName" width="100%"
							headerAlign="center" align="left" allowSort="true">
							企业名称<input id="orgFilter" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect_1" />
						</div>
					</div>
				</div>
			</div>
			<div showCollapseButton="true">
				<div id="datagrid2" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="100"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagrid1DrawCell_2" onrowdblclick="gridRowDbClick_2"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div type="checkcolumn" width="40px" align="center"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch_2">清除
							</a>
						</div>
						<div field="CardID" width="200px" headerAlign="center"
							align="left" allowSort="true">
							身份证号<input id="filter1" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect_2" emptyText="筛选..."
								onenter="onselect_2" />
						</div>
						<div field="UserName" width="80px" headerAlign="center"
							align="left" allowSort="true">
							姓名<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect_2" emptyText="筛选..."
								onenter="onselect_2" />
						</div>
						<div field="Sex" width="60px" headerAlign="center" align="center"
							allowSort="true">
							性别<input id="filter3" property="filter" class="mini-combobox"
								style="width: 100%;" data="sexData" onValueChanged="onselect_2"
								emptyText="筛选..." onenter="onselect_2" />
						</div>
						<div field="SourceName" width="80px" headerAlign="center"
							align="left" allowSort="true">
							来源<input id="filter4" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect_2" emptyText="筛选..."
								onenter="onselect_2" />
						</div>
						<div field="EmployTypeName" width="60px" headerAlign="center"
							align="left" allowSort="true">
							工种<input id="filter5" property="filter" class="mini-combobox"
								textField="EmployType" valueField="TypeNo" style="width: 100%;"
								url="<c:url value='/common/type/employ_type'></c:url>"
								onValueChanged="onselect_2" emptyText="筛选..."
								onenter="onselect_2" />
						</div>
						<div field="EmployTime" width="140px"
							dateFormat="yyyy-MM-dd HH:mm" headerAlign="center" align="center"
							allowSort="true">入职时间</div>
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
			</div>
		</div>
	</div>


	<script type="text/javascript">
		mini.parse();

		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var type = '${type}';

		var filterHelper = gridFilter();
		var filterHelper2 = gridFilter();

		var typeBtn = mini.get("typeBtn");
		var datagrid1 = mini.get("treegrid1");
		var datagrid2 = mini.get("datagrid2");
		var splitpan = mini.get("splitterPan");
		var orgFilter = mini.get("orgFilter");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");
		var filter5 = mini.get("filter5");
		var orgNo = null;
		var orgName = null;
		var state = 1;

		var starting = mini.get("starting");
		var ending = mini.get("ending");

		$(function() {
			loadGrid1();
		});
		function onselect_1() {
			var filterValue0 = orgFilter.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("OrgName",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function onselect_2() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			var filterValue4 = filter4.getValue();
			var filterValue5 = filter5.getValue();
			var filterStarting = starting.getValue();
			var filterEnding = ending.getValue();
			filterHelper2.clearFilterData();

			if (filterStarting && filterEnding && filterStarting > filterEnding) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (filterValue1 != "") {
				c
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("UserName",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("Sex",
						filterValue3, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue4 != "") {
				var filterdata = filterHelper.formFilterData("SourceName",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue5 != "") {
				var filterdata = filterHelper.formFilterData("EmployType",
						filterValue5, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterStarting != "") {
				var filterdata = filterHelper.formFilterData("CreateTime",
						filterStarting, '', 'GREATER_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterEnding != "") {
				var filterdata = filterHelper.formFilterData("CreateTime",
						filterEnding, '', 'LESS_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			loadGrid2(orgNo);

		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/org/list' />";
			datagrid1.setUrl(url);
			datagrid1.load(postData, function() {
				var row = datagrid1.getRow(0);
				if (row) {
					datagrid1.setSelected(row);
					orgNo = row.OrgNo;
					orgName = row.OrgName;
					$('.nameTitle').html(orgName);
					loadGrid2(orgNo);
				}
			});
		}
		function orgSelect() {
			var row = datagrid1.getSelected();
			if (!row) {
				return;
			}
			orgNo = row.OrgNo;
			if (!orgNo) {
				mini.alert('数据有误 ，请联系管理员处理！');
				return;
			}
			orgName = row.OrgName;
			$('.nameTitle').html(orgName);
			loadGrid2(orgNo);
		}
		function loadGrid2(orgNo) {
			var filterdata = filterHelper.formFilterData("Manager",
					6, '', 'LESS_EQUALS', 'AND');
			filterHelper2.addFilterData(filterdata);
			var filterData = filterHelper2.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/user/list/' />" + orgNo + '/1';
			datagrid2.load(url);
			datagrid2.load(postData);
		}
		function chageState() {
			state = this.getValue();
			var row = datagrid1.getSelected();
			if (!row || !row.OrgNo) {
				mini.alert('请选择企业！');
				return;
			}

			loadGrid2(row.OrgNo);
		}
		function removeSearch() {
			orgFilter.setValue();
			orgFilter.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}
		function removeSearch_2() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter4.setValue();
			filter4.setText();
			filter5.setValue();
			starting.setValue();
			starting.setText();
			ending.setValue();
			ending.setText();
			filterHelper2.clearFilterData();
			loadGrid2(orgNo);
		}
		function ondatagridDrawCell(e) {
			var field = e.field;
			var row = e.row;
			var grade = row.Grade;
			var cellCls = null;
			switch (grade) {
			case 1:
				cellCls = "deepDark";
				break;
			case 2:
				cellCls = "normalDark";
				break;
			default:
				cellCls = "lowDark";
				break;
			}
			e.cellCls = cellCls;
		}
		function ondatagrid1DrawCell_2(e) {
			var row = e.row;
			var field = e.field;
			if (field == "Action") {
				var id = row.EmployId;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:update('
						+ id + ')">[详细]</a>';
			}

			if (field == "Sex") {
				var value = e.value;
				if (value) {
					e.cellHtml = (value == 1 || value == '1') ? '男' : '女';
				}
			}
		}
		function treeBeforeLoad(e) {
			var filterData = filterHelper.getFilterData();
			e.data.filterdata = mini.encode(filterData);
		}
		function ok() {
			var rows = datagrid2.getSelecteds();
			if(rows.length < 1){
				mini.alert('请选择人员！');
				return;
			}
			var id= "";
			for(var i = 0; i<rows.length;i++){
				if(id == ""){
					id = rows[i].EmployId;
				}else{
					id += ","+rows[i].EmployId;
				}
			}
			var url = rootPath + "/auth/save/"+type;
			$.ajax({
				url : url,
				method : "post",
				dataType : "json",
				data : {
					"ids" : id
				},
				success : function(data) {
					if (data) {
						top.commonTools.showTip("操作成功！", 1);
						CloseWindow("ok");
					} else {
						top.commonTools.showTip("操作失败！", 2);
						CloseWindow("ok");
					}
				},
				error : function() {
					top.commonTools.showTip("操作发生错误！", 2);
				}

			});
		}
		//取消
		function cancel(){
			CloseWindow("cancel");
		}
		//关闭当前弹出窗口并返回一个值告诉父页面该做什么操作
		function CloseWindow(action) {            
             if (window.CloseOwnerWindow) {
            	 return window.CloseOwnerWindow(action);
             } else {
            	 window.close();            
             }
        }
	</script>
</body>
</html>